package com.kimo3412.gradehub.controller;

import com.kimo3412.gradehub.entity.Course;
import com.kimo3412.gradehub.response.ApiResponse;
import com.kimo3412.gradehub.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/listAll")
    public ResponseEntity<ApiResponse<List<Course>>> listAllCourses() {
        List<Course> courses = courseService.findAllCourses();
        return ResponseEntity.ok(new ApiResponse<>(200, "Success", courses));
    }

    @GetMapping("/getById/{courseId}")
    public ResponseEntity<ApiResponse<Course>> getCourseById(@PathVariable Long courseId) {
        Course course = courseService.findCourseById(courseId);
        return ResponseEntity.ok(new ApiResponse<>(200, "Success", course));
    }

    @PostMapping("/add")
    public ResponseEntity<ApiResponse<Course>> addCourse(@RequestBody Course course) {
        Course savedCourse = courseService.addCourse(course);
        return ResponseEntity.ok(new ApiResponse<>(201, "Course added successfully", savedCourse));
    }
}
